package com.zhengsr.latte.ui.loader;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.zhengsr.latte.utils.DimenUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhengshaorui on 2018/4/8.
 */

public class LatteLoader {
    private static final String TAG = "LatteLoader";
    private static final int DIALOG_SIZE_SCALE = 4;
    private static final List<CusDialog> DIALOGS = new ArrayList<>();
    public static void showDialog(Context context, View contentView){
       /* AppCompatDialog dialog = new AppCompatDialog(context, R.style.lattedialog);
        dialog.setContentView(contentView);
        dialog.show();
        
        Window dialogwindow = dialog.getWindow();
        if (dialogwindow != null){
            WindowManager.LayoutParams params = dialogwindow.getAttributes();
            params.width = dialogwidth / DIALOG_SIZE_SCALE;
            params.height = dialogheight / DIALOG_SIZE_SCALE;
            params.gravity = Gravity.CENTER;

            dialogwindow.setAttributes(params);
        }*/
        int dialogwidth = DimenUtils.getScreenWidth();
        int dialogheight = DimenUtils.getScreenHeight();
        Log.d(TAG, "zsr --> showDialog: "+dialogheight+" "+dialogwidth);
       CusDialog cusDialog = new CusDialog.Builder()
               .setContext(context)
               .setDialogView(contentView)
               .setWidth(DimenUtils.getScreenWidth() / DIALOG_SIZE_SCALE)
               .setHeight(DimenUtils.getScreenWidth() / DIALOG_SIZE_SCALE)
               .setOutSideDimiss(true)
               .builder();
        DIALOGS.add(cusDialog);

    }

    public static void stopDialog(){
        for (CusDialog dialog : DIALOGS) {
            if (dialog.isShowing()){

                dialog.cancel();
            }
        }
        DIALOGS.clear();
    }
}
